//multisignal.c
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <string.h>
#define INPUTLEN 20
char input[INPUTLEN];
void inthandler(int s)
{
    printf(" I have Received signal %d .. waiting\n", s);
    sleep(2);
    printf("I am Leaving inthandler \n");
    signal(SIGINT, inthandler);
}
void quithandler(int s)
{
    printf(" I have Received signal %d .. waiting\n", s);
    sleep(3);
    printf("I am Leaving quithandler \n");
    signal(SIGQUIT, quithandler);
}
void main()
{
    signal(SIGINT, inthandler);
    signal(SIGQUIT, quithandler);
    do {
        printf("please input a message\n");
        int nchars = read(0, input, INPUTLEN-1);
        if (nchars == -1)
            perror("read returned an error");
        else {
            input[nchars] = '\0';
            printf("You have inputed: %s\n", input);
        }
    } while (strncmp(input, "quit", 4) != 0);
}
